﻿using System;
using System.IO;
using System.Linq;
using System.Windows.Forms;

namespace FileExplorer
{
    public static class Program
    {
        public static FileExplorerForm MainForm { get; private set; }

        [STAThread]
        public static void Main(params string[] Args)
        {
#if !DEBUG
            if(Args == null || Args.Length == 0)
                return;
#endif
#if DEBUG
            if(Args == null || Args.Length == 0)
            {
                var directory = new DirectoryInfo(Application.StartupPath);
                Args = directory.GetDirectories().Cast<FileSystemInfo>()
                                .Concat(directory.GetFiles())
                                .Select(f => f.FullName)
                                .ToArray();
            }
#endif

            var infos = Args.Select(CreateInfo).Where(i => i != null);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            MainForm = new FileExplorerForm();

            MainForm.AddFiles(infos.Where(i => i != null));

            Application.Run(MainForm);
        }

        private static FileSystemInfo CreateInfo(string str)
        {
            return Directory.Exists(str)
                               ? (FileSystemInfo)new DirectoryInfo(str)
                               : File.Exists(str) ? new FileInfo(str) : null;
        }
    }
}
